/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.sms.client.impl;

import com.tbit.main.sms.client.SmsClient;
import com.tbit.main.sms.client.dto.SmsSendReqDTO;
import com.tbit.main.sms.properties.SmsChannelProperties;
import com.tbit.main.util.ThreadPoolHelper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.1.0
 * @since 2024/7/12 9:50
 */
@Slf4j
public abstract class AbstractSmsClient implements SmsClient {

    protected volatile SmsChannelProperties properties;

    public AbstractSmsClient(SmsChannelProperties properties) {
        this.properties = properties;
    }

    @Override
    public void send(SmsSendReqDTO dto) {
        ThreadPoolHelper.submit(() -> {
            try {
                doSend(dto);
            } catch (Throwable e) {
                log.error(e.getMessage());
            }
        });
    }

    protected abstract void doSend(SmsSendReqDTO dto) throws Throwable;

    @Override
    public void init() {
        doInit();
    }

    protected abstract void doInit();
}
